#include "protreewidget.h"
#include "slideshowdlg.h"
#include "ui_slideshowdlg.h"

SlideShowDlg::SlideShowDlg(QTreeWidgetItem *first_item,
                           QTreeWidgetItem *last_item,QWidget *parent): QDialog(parent),
    ui(new Ui::SlideShowDlg),_first_item(first_item),_last_item(last_item)
{

    ui->setupUi(this);
    auto * prelistWid = ui->preListWidget;
    connect(ui->picAnimation, &PicAnimationWid::SigUpPreList, prelistWid,&PreListWid::SlotUpPreList);

    connect(ui->picAnimation, &PicAnimationWid::SigSelectItem, prelistWid, &PreListWid::SlotUpSelect);
    //连接下方预览条点击与上方动画区图片显示

    connect(prelistWid, &PreListWid::SigUpSelectShow,
            ui->picAnimation, &PicAnimationWid::SlotUpSelectShow);
    ui->playBtn->SetIcons(":/icon/play.png",":/icon/play_hover.png",":/icon/play_press.png",
                          ":/icon/pause.png",":/icon/pause_hover.png",":/icon/pause_press.png");
    //连接动画和按钮显示状态
    connect(ui->picAnimation,&PicAnimationWid::SigStart, ui->playBtn, &PicStateBtn::SlotStart);
    connect(ui->picAnimation,&PicAnimationWid::SigStop, ui->playBtn, &PicStateBtn::SlotStop);
    //连接开始暂停.
    connect(ui->playBtn,&PicStateBtn::clicked,ui->picAnimation,&PicAnimationWid::SlotChange);
    //隐藏边框的叉号。
    setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);

    ui->closeBtn->SetIcons(":/icon/closeshow.png",":/icon/closeshow_hover.png",
                           ":/icon/closeshow_press.png");
    //连接关闭按钮

    connect(ui->closeBtn, &QPushButton::clicked, this, &SlideShowDlg::SlotClose);


    ui->slidepreBtn->SetIcons(":/icon/previous.png",
                             ":/icon/previous_hover.png",
                             ":/icon/previous_press.png");
    ui->slidenextBtn->SetIcons(":/icon/next.png",
                               ":/icon/next_hover.png",
                               ":/icon/next_press.png");
    //连接向后查看按钮
    connect(ui->slidenextBtn, &QPushButton::clicked,this,&SlideShowDlg::SlotSlideNext);
    //连接向前查看按钮
    connect(ui->slidepreBtn, &QPushButton::clicked,this,&SlideShowDlg::SlotSlidePre);

    auto * _protree_widget = dynamic_cast<ProTreeWidget*>(parent);

    //连接音乐启动信号
    connect(ui->picAnimation, &PicAnimationWid::SigStartMusic, _protree_widget,
            &ProTreeWidget::SlotStartMusic);
    //连接音乐关闭信号
    connect(ui->picAnimation,&PicAnimationWid::SigStopMusic, _protree_widget,
            &ProTreeWidget::SlotStopMusic);
    ui->picAnimation->SetPixmap(_first_item);
    ui->picAnimation->Start();
}

SlideShowDlg::~SlideShowDlg()
{
    delete ui;
}

void SlideShowDlg::SlotSlideNext()
{
    ui->picAnimation->SlideNext();
}

void SlideShowDlg::SlotSlidePre()
{
    ui->picAnimation->SlidePre();
}

void SlideShowDlg::SlotClose()
{
    ui->picAnimation->Stop();
    close();
}
